package demo1;

import java.util.*;

public class Main {

//    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
//        int n = in.nextInt(), m = in.nextInt();
//        int[] num1 = new int[n];
//        int[] num2 = new int[m];
//        for(int i = 0; i < n; i++){
//            num1[i] = in.nextInt();
//        }
//        for(int i = 0; i < m; i++){
//            num2[i] = in.nextInt();
//        }
//
//        Arrays.sort(num1);
//        Arrays.sort(num2);
//        int cur1 = 0, cur2 = 0;
//        while(cur1 < n && cur2 < m){
//            if(num1[cur1] > num2[cur2]){
//                System.out.print(num2[cur2] + " ");
//                cur2++;
//            }else{
//                System.out.print(num1[cur1] + " ");
//                cur1++;
//            }
//        }
//        while(cur1 != n) { System.out.print(num1[cur1++] + " ");}
//        while(cur2 != m) { System.out.print(num2[cur2++] + " ");}
//    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        int x = 0;
        while(n-- != 0){
            x = in.nextInt();
            set.add(x);
        }
        while(m-- != 0){
            x = in.nextInt();
            set.add(x);
        }

        for(int a : set){
            System.out.print(a + " ");
        }
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        int[] arr1 = new int[n];
        int[] arr2 = new int[m];
        for(int i = 0; i < n; i++){
            arr1[i] = in.nextInt();
        }
        for(int i = 0; i < m; i++){
            arr2[i] = in.nextInt();
        }

        Arrays.sort(arr1);
        Arrays.sort(arr2);
        int ret = 0, t = 0, c1 = 0, c2 = 0;
        while(c1 < n && c2 < m){
            if(arr1[c1] > arr2[c2]){
                if(t != arr2[c2]){
                    t = arr2[c2];
                    System.out.print(t + " ");
                }
                c2++;
            }else{
                if(t != arr1[c1]){
                    t = arr1[c1];
                    System.out.print(t + " ");
                }
                c1++;
            }
        }
        while(c1 != n) {
            if(t != arr1[c1]){
                t = arr1[c1];
                System.out.print(t + " ");
            }
            c1++;
        }
        while(c2 != m) {
            if(t != arr2[c2]){
                t = arr2[c2];
                System.out.print(t + " ");
            }
            c2++;
        }
    }

    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int n = s.length;

        int[][] dp = new int[n][n];
        for(int i = n - 1; i >= 0; i--){
            dp[i][i] = 1;
            for(int j = i + 1; j < n; j++){
                if(s[i] == s[j]){
                    dp[i][j] = dp[i + 1][j - 1] + 2;
                }else{
                    dp[i][j] = Math.max(dp[i + 1][j], dp[i][j - 1]);
                }
            }
        }
        System.out.println(dp[0][n - 1]);
    }
}
